<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- c1 c3-->
    <form id="form">
      <input type="text" name="username" />
      <input type="password" name="password" />
      <input type="button" id="btn" value="提交" />
    </form>
    <script>
      let btn = document.getElementById('btn')
      // c4
      let form = document.getElementById('form')
      btn.onclick = function () {
        // c2
        let formData = new FormData(form)
        // c5
        let xhr = new XMLHttpRequest()
        xhr.open('post', 'http://localhost:3000/formData')
        // c6
        xhr.send(formData)
        // c7
        xhr.onload = function(){
          if(xhr.status == 200) {
            console.log(xhr.responseText)
          }
        }
      }
    </script>
  </body>
</html>
